RM.Pages.Functions.Groups_New = {
    Insert : function(){
        RM.Pages.Groups_New_Panel.getForm().submit({
            success: function(form, action) {
                RM.Pages.Functions.Groups_ListJson();
            },
            waitMsg: RM.Translate.Common.Saving,
            waitTitle: RM.Translate.Common.PleaseWait
        });
    },
    Cancel : function(){
        RM.Pages.Functions.Groups_ListJson();
    }
}

RM.Pages.Groups_New_Toolbar = {
    xtype : "panel",
    id : "rm_pages_groups_new_toolbar",
    bodyBorder : false,
    html : RM.Common.getToolbar([
        {image: RM.BaseLargeImageURL+"save.gif", label: RM.Translate.Admin.Groups.New.Save, link: "RM.Pages.Functions.Groups_New.Insert()"},
        {image: RM.BaseLargeImageURL+"cancel.gif", label: RM.Translate.Common.Cancel, link: "RM.Pages.Functions.Groups_New.Cancel()"}
    ])
};
RM.Toolbars.push(RM.Pages.Groups_New_Toolbar);


RM.Pages.Groups_New_Language_Combo = new Ext.form.ComboBox({
    id : "new_groups_iso",
    hiddenName : "new_group_iso_hidden",
    xtype : "combo",
    cls: 'RM_language_selection_combo',
    typeAhead: true,
    fieldLabel: RM.Translate.Admin.Groups.New.Language,
    forceSelection: true,
    triggerAction: 'all',
    selectOnFocus: true,
    store: RM.Languages,
    autoLoad: true,
    bodyBorder : false,
    frame : false,
    width: 180,
    value: "English"
});

RM.Pages.Groups_New_Language = new Ext.Panel({
    id : "rm_pages_groups_new_language",
    layout: 'form',
    bodyBorder : false,
    frame : false,
    items : [
        RM.Pages.Groups_New_Language_Combo
    ]
});

RM.Pages.Groups_New_Title = {
    xtype : "panel",
    id : "rm_pages_groups_new_title",
    bodyBorder : false,
    frame : false,
    html : "<span class='RM_Title_Language_Bar_img'><img src='"+RM.BaseMenuImageURL+"unit.png'></span>&nbsp;<span class='RM_Title_Language_Bar_text'>"+RM.Translate.Admin.Groups.New.Title+"</span>"
};

RM.Pages.Groups_New_Language_Panel = new Ext.Panel({
    id : "rm_pages_groups_new_language_selection",
    layout: 'column',
    frame : false,
    baseCls: "x-panel-header",
    items : [
        RM.Pages.Groups_New_Title,
        RM.Pages.Groups_New_Language
    ]
});

RM.Pages.Functions.Groups_New_Main = function () {
    Ext.getCmp('new_group[name]').setValue('');
    Ext.getCmp('new_group_main_unit_id').setValue('');
    Ext.getCmp('new_group_published').setValue(1);

    Ext.getCmp('toolbar_panel').layout.setActiveItem('rm_pages_groups_new_toolbar');
    Ext.getCmp('content-panel').layout.setActiveItem('rm_pages_groups_new');
};

RM.Pages.Groups_New_Panel = new Ext.FormPanel({
    xtype: 'form',
    bodyStyle: 'padding: 0 10px 0 10px',
    url : RM.Common.AssembleURL({
        controller: 'Groups_New',
        action: 'insertjson'
    }),
    items: [{
        xtype: 'fieldset',
        labelWidth: 150,
        title: RM.Translate.Admin.Groups.New.GroupConfiguration,
        items: [{
            id: 'new_group[name]',
            name: 'new_group[name]',
            fieldLabel: RM.Translate.Admin.Groups.New.Name,
            allowBlank: false,
            xtype: 'textfield'
        },{
            id : "new_group_main_unit_id",
            hiddenName: "new_group[main_unit_id]",
            name: "new_group_main_unit_id",
            xtype : "combo",
            width: "207",
            allowBlank: false,
            typeAhead: true,
            fieldLabel: RM.Translate.Admin.Groups.New.Unit,
            triggerAction: 'all',
            selectOnFocus: true,
            valueField: 'id',
            displayField: 'name',
            minChars: 1,
            pageSize: 10,
            resizable: true,
            minListWidth: 220,
            store: new Ext.data.JsonStore({
                id:'id',
                root:'data',
                totalProperty:'total',
                fields:[
                    {name:'id', type:'int'},
                    {name:'name', type:'string'}
                ],
                url : RM.Common.AssembleURL({
                    controller: 'Units',
                    action: 'listJson'
                })
            })
        },{
            id : "new_group_published",
            hiddenName: "new_group[published]",
            name: "new_group_published",
            xtype : "combo",
            typeAhead: true,
            fieldLabel: RM.Translate.Common.Published,
            forceSelection: true,
            mode: "local",
            triggerAction: 'all',
            selectOnFocus: true,
            valueField: 'value',
            displayField: 'text',
            allowBlank: false,
            store: new Ext.data.JsonStore({
                fields:[
                    {name:'value', type:'int'},
                    {name:'text', type:'string'}
                ],
                data: RM.Translate.Common.JSON.YesNo
            }),
            labelWidth: 190,
            width: 50
        }]
    }]
});

RM.Pages.Groups_New = new Ext.Panel({
    id: "rm_pages_groups_new",
    items: [
        RM.Pages.Groups_New_Language_Panel,
        RM.Pages.Groups_New_Panel
    ]
});

RM.Main.Pages.push(RM.Pages.Groups_New);